package itsm.isperp.module.controller.db;

import itsm.isperp.module.entity.db.DbEntityFieldControl;
import itsm.isperp.module.service.db.DbEntityFieldControlService;
import itsm.isperp.module.service.db.DbEntityFieldService;
import itsm.isperp.module.service.db.DbEntityService;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 实体字段控制器
 * 
 * @author lizx
 * @date 2013-5-5
 */
@Controller
@RequestMapping("db/dynamicControl")
public class DbDynamicControlController {

	@Autowired
	DbEntityService dbEntityService;

	@Autowired
	DbEntityFieldService dbEntityFieldService;

	@Autowired
	DbEntityFieldControlService dbEntityFieldControlService;

	/**
	 * 根据分页器获取实体列表的json格式数据
	 * 
	 * @param req
	 *            {@link HttpServletRequest} http请求
	 * @return json格式数据
	 */
	@RequestMapping("getDatasource")
	@ResponseBody
	public List<Map<String, Object>> getDatasource(HttpServletRequest req) {
		String datasourceEntityId = req.getParameter("datasourceEntityId");

		String controlType = req.getParameter("controlType");
		String valueField = req.getParameter("valueField");
		String displayField = req.getParameter("displayField");
		String filter = req.getParameter("filter");

		DbEntityFieldControl control = new DbEntityFieldControl();
		control.setDatasourceEntityId(datasourceEntityId);
		control.setControlType(controlType);
		control.setValueField(valueField);
		control.setDisplayField(displayField);
		control.setFilter(filter);

		return dbEntityFieldControlService.getDatasource(control);

	}

}
